import React from 'react';
import {
  ModalForm,
} from '@ant-design/pro-form';
import {connect} from "dva";
import {GlobalModelState} from "@/models/global";
import {PermissionProps} from "@/components/Permission/index";
import {ModalFormProps} from "@ant-design/pro-form/lib/layouts/ModalForm";

interface ModalPermissionProps extends PermissionProps,ModalFormProps{

}

const ModalPermission:React.FC<ModalPermissionProps> = (props) => {
  const { functionKey,functions } = props;
  if(functionKey&&functions&&functions.some(item=>item.path===functionKey)){
    const newProps:any={...props};
    delete newProps.dispatch;
    return (
      <ModalForm {...newProps}>
        {props.children}
      </ModalForm>
    );
  }

  const newProps:any={...props};
  delete newProps.dispatch;
  delete newProps.functions;
  delete newProps.functionKey;
  return (
    <ModalForm {...newProps}>
      {props.children}
    </ModalForm>
  );
};

export default connect(({global}:{
  global: GlobalModelState;
}) => ({
  functions:global.profile.functions
}))(ModalPermission);
